from industrialai.db.model import Base, Role, User
from sqlalchemy.orm import sessionmaker
import os
from sqlalchemy import create_engine

def init_db():
    DB_URL = os.getenv('db_url') or \
    "sqlite:///C:\\Users\\23360\\Desktop\\dhuProject\\pecan-swagger\\examples\\industrial-ai-apiserver\\industrialai.db?check_same_thread=False"
    engine = create_engine(DB_URL, echo=True)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    Session = sessionmaker(bind=engine)
    session = Session()

    session.add_all([
        Role(title="expert"),
        Role(title="government"),
        Role(title="enterpriseAdmin"),
        Role(title="member"),
        Role(title="admin"),
        User(account="admin", pwd="123456", roleId=3),
        User(account="member", pwd="123456", roleId=4),
        User(account="root", pwd="123456", roleId=5)
    ])
    session.commit()


init_db()
